#include"Differ.cpp"
#include<stdlib.h>

int main()
{
    printf("Available commands sin/cos EXP, ^, log\n");
    node_t* root = getG0();
    FILE* f = NULL;
    if (!(f = fopen("output", "w")))
        return EXIT_FAILURE;

    printTreeP(root, f);

    FILE* f_tex = NULL;
    if (!(f_tex = fopen("ez.tex", "w")))
        {printf("\nCannot open TexFile.\n"); return EXIT_FAILURE;}

    dumpPreambule(f_tex);

    char arg[20] ="";
    printf("Choose your Variable\n>");
    scanf("%s", arg);

    fprintf(f_tex,"Hello there. I want to show you how to diferentiate it by %s:", arg);
    dumpFormula(f_tex, root);
    fprintf(f_tex,"\n\nSo we need to start. Let's do it like little children:\n\n");


    fprintf(f, "\n");
    root = differ(root, arg);
    printTreeP(root, f);

    dumpFormula(f_tex, root);
    fprintf(f_tex, "\n\nNeed to optimize it. No optimizations by my own hands.\n\n");

    optimizeTree(root, f_tex, f);
    dumpEndOfDoc(f_tex);

    fprintf(f, "\n");
    printTreeP(root, f);

    fclose(f);    f = NULL;
    fclose(f_tex);f_tex = NULL;

    system("pdflatex ez.tex");
    return 0;
}
